﻿@{
    ViewBag.Title = "门诊费用分析";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<head>
    <meta charset="utf-8">
    <script src="~/Content/js/echarts.min.js"></script>
    <style>
        .content {
            height: 49.5%;
            width: 100%;
            display: flex;
            flex-direction: row;
            justify-content: space-between;
        }
        .bk {
            border-radius: 10px;
            background-color: white;
        }
        .down_border {
            border-bottom: 1px solid #e6e6e6;
        }
    </style>
</head>

<div class="panel panel-default">
    <table class="form">
        <tr>
            <th class="formTitle" id="xzsjtext">类型：</th>
            <td class="formValue" style="width:150px">
                <select id="dateType" class="form-control" onchange="updateSjType()">
                    <option value="1">年</option>
                    <option value="2">月</option>
                    <option value="3">日</option>
                </select>
            </td>
            <th class="formTitle" id="xzsjtext">时间：</th>
            <td class="formValue" style="width:150px">
                <input id="rSJ" type="text" class="form-control input-wdatepicker" />
            </td>
            <td class="formValue" style="padding-left:20px;">
                <input type="button" id="btn_search" onclick="submit();" class="btn btn-primary btn-md" value="查询" style="width:55px" />
            </td>
        </tr>
    </table>
</div>

<div id="main_div" style="display:flex;flex-wrap:wrap;align-content:space-between;">
    <div class="content">
        <div style="width:49.95%" class="bk">
            <div class="panel-heading down_border">
                <i class="fa fa-table fa-lg" style="margin-right:5px;"></i>门诊费用分类分析
            </div>
            <table id="gridJSListmzfyflfx"></table>
        </div>
        <div id="main1" style="width:49.5%;" class="bk"></div>
    </div>

    <div class="content">
        <div style="width:49.95%;" class="bk">
            <div class="panel-heading down_border">
                <i class="fa fa-table fa-lg" style="margin-right:5px;"></i>患者人均费用分析
            </div>
            <table id="gridJSListhzrjfyfx"></table>
        </div>
        <div id="main2" style="width:49.5%;" class="bk"></div>
    </div>
</div>

<script>

    var myDate = new Date();
    $(function () {
        $('#main_div').height($(window).height() - 60);
        //默认设置时间类型为月
        $("#dateType").val("2");
        $('#rSJ').attr('onfocus', "WdatePicker({ dateFmt: 'yyyy-MM' })");
        $('#rSJ').val(myDate.getFullYear() + "-" + (parseInt(myDate.getMonth()) + 1));

        gridJSListData();
        getData();
    });

    //根据年月获取月天数
    function getDaysInMonth(year, month) {
        return new Date(year, month, 0).getDate();
    }
    //改变时间类型
    function updateSjType() {
        $('#rSJ').val("");
        let dateType = $("#dateType").val();
        if (dateType == "1") {//年
            $('#rSJ').attr('onfocus', "WdatePicker({ dateFmt: 'yyyy' })");
            $('#rSJ').val(myDate.getFullYear());
        }
        if (dateType == "2") {//月
            $('#rSJ').attr('onfocus', "WdatePicker({ dateFmt: 'yyyy-MM' })");
            $('#rSJ').val(myDate.getFullYear() + "-" + (parseInt(myDate.getMonth()) + 1));
        }
        if (dateType == "3") {//日
            $('#rSJ').attr('onfocus', "WdatePicker({ dateFmt: 'yyyy-MM-dd' })");
            $('#rSJ').val(myDate.getFullYear() + "-" + (parseInt(myDate.getMonth()) + 1) + "-" + myDate.getDate());
        }
    }
    //组装请求参数
    function getSearchData() {
        let ksrq = '';
        let jsrq = '';
        let dateType = $("#dateType").val();
        let nowDate = $("#rSJ").val();
        if (dateType == "1") {//年
            ksrq = nowDate + "-" + "01-01 00:00:00";
            jsrq = nowDate + "-" + "12-31 23:59:59";
        }
        if (dateType == "2") {//月
            let array = nowDate.split("-");
            ksrq = array[0] + "-" + array[1] + "-01 00:00:00";
            let days = getDaysInMonth(array[0], array[1]);
            jsrq = array[0] + "-" + array[1] + "-" + days + " 23:59:59";
        }
        if (dateType == "3") {//日
            ksrq = nowDate + " 00:00:00";
            jsrq = nowDate + " 23:59:59";
        }
        return { ksrq: ksrq, jsrq: jsrq, rtype: dateType };
    }

    function getData()
    {
        $.ajax({
            type: "Post",
            url: "/DeanInquiryManage/OutpatientCostAnalysis/GetMzfyflfx_tb",
            data: getSearchData(),
            dataType: "json",
            success: function (ajaxresp) {
                var Titledata = ['product'];
                var valuedata = ajaxresp;
                for (var i = 0; i < ajaxresp.length; i++) {
                    Titledata.push(ajaxresp[i].年份);
                }
                setTimeout(function initEcharts1() {
                    var option;
                    var chartDom = document.getElementById('main1');
                    var myChart = echarts.init(chartDom);
                    window.addEventListener('resize', function () {
                        myChart.resize();
                    });
                    option = {
                        legend: {
                            orient: 'vertical',
                            bottom: 'bottom'
                        },
                        tooltip: {
                            trigger: 'axis',
                            showContent: false
                        },
                        dataset: {
                            source: [
                                Titledata,
                                ['总费用', valuedata[0].总费用, valuedata[1].总费用, valuedata[2].总费用, valuedata[3].总费用, valuedata[4].总费用, valuedata[5].总费用, valuedata[6].总费用],
                                ['药品费', valuedata[0].药品费, valuedata[1].药品费, valuedata[2].药品费, valuedata[3].药品费, valuedata[4].药品费, valuedata[5].药品费, valuedata[6].药品费],
                                ['耗材费', valuedata[0].耗材费, valuedata[1].耗材费, valuedata[2].耗材费, valuedata[3].耗材费, valuedata[4].耗材费, valuedata[5].耗材费, valuedata[6].耗材费],
                                ['检验费', valuedata[0].检验费, valuedata[1].检验费, valuedata[2].检验费, valuedata[3].检验费, valuedata[4].检验费, valuedata[5].检验费, valuedata[6].检验费],
                                ['检查费', valuedata[0].检查费, valuedata[1].检查费, valuedata[2].检查费, valuedata[3].检查费, valuedata[4].检查费, valuedata[5].检查费, valuedata[6].检查费],
                                ['资料费', valuedata[0].资料费, valuedata[1].资料费, valuedata[2].资料费, valuedata[3].资料费, valuedata[4].资料费, valuedata[5].资料费, valuedata[6].资料费],
                                ['其他', valuedata[0].其他, valuedata[1].其他, valuedata[2].其他, valuedata[3].其他, valuedata[4].其他, valuedata[5].其他, valuedata[6].其他]
                            ]
                        },
                        xAxis: { type: 'category' },
                        yAxis: { gridIndex: 0 },
                        grid: { top: '55%' },
                        series: [
                            {
                                type: 'line',
                                smooth: true,
                                seriesLayoutBy: 'row',
                                emphasis: { focus: 'series' }
                            },
                            {
                                type: 'line',
                                smooth: true,
                                seriesLayoutBy: 'row',
                                emphasis: { focus: 'series' }
                            },
                            {
                                type: 'line',
                                smooth: true,
                                seriesLayoutBy: 'row',
                                emphasis: { focus: 'series' }
                            },
                            {
                                type: 'line',
                                smooth: true,
                                seriesLayoutBy: 'row',
                                emphasis: { focus: 'series' }
                            },
                            {
                                type: 'line',
                                smooth: true,
                                seriesLayoutBy: 'row',
                                emphasis: { focus: 'series' }
                            },
                            {
                                type: 'line',
                                smooth: true,
                                seriesLayoutBy: 'row',
                                emphasis: { focus: 'series' }
                            },
                            {
                                type: 'line',
                                smooth: true,
                                seriesLayoutBy: 'row',
                                emphasis: { focus: 'series' }
                            },
                            {
                                type: 'pie',
                                id: 'pie',
                                radius: '30%',
                                center: ['50%', '25%'],
                                emphasis: {
                                    focus: 'self'
                                },
                                label: {
                                    formatter: "{b}: {@('@')" + ajaxresp[0].年份 + "} ({d}%)"
                                    //formatter: '{b}:({d}%)'
                                },
                                encode: {
                                    itemName: 'product',
                                    value: ajaxresp[0].年份 ,
                                    tooltip: ajaxresp[0].年份
                                }
                            }
                        ]
                    };
                    myChart.on('updateAxisPointer', function (event) {
                        const xAxisInfo = event.axesInfo[0];
                        if (xAxisInfo) {
                            const dimension = xAxisInfo.value + 1;
                            myChart.setOption({
                                series: {
                                    id: 'pie',
                                    label: {
                                        //formatter: '{b}:({d}%)'
                                        formatter: '{b}: {@("@")[' + dimension + ']} ({d}%)'
                                    },
                                    encode: {
                                        value: dimension,
                                        tooltip: dimension
                                    }
                                }
                            });
                        }
                    });
                    myChart.setOption(option);
                });
            }
        });
        
        $.ajax({
            type: "Post",
            url: "/DeanInquiryManage/OutpatientCostAnalysis/GetHzrjfyfx_tb",
            data: getSearchData(),
            dataType: "json",
            success: function (ajaxresp) {
                var Titledata = ['product'];
                var valuedata = ajaxresp;
                for (var i = 0; i < ajaxresp.length; i++) {
                    Titledata.push(ajaxresp[i].年份);
                }
                setTimeout(function initEcharts2() {
                    var option;
                    var chartDom = document.getElementById('main2');
                    var myChart = echarts.init(chartDom);
                    window.addEventListener('resize', function () {
                        myChart.resize();
                    });
                    option = {
                        legend: {
                            orient: 'vertical',
                            bottom: 'bottom'
                        },
                        tooltip: {
                            trigger: 'axis',
                            showContent: false
                        },
                        dataset: {
                            source: [
                                Titledata,
                                ['人均总费用', valuedata[0].总费用, valuedata[1].总费用, valuedata[2].总费用, valuedata[3].总费用, valuedata[4].总费用, valuedata[5].总费用, valuedata[6].总费用],
                                ['人均药品费', valuedata[0].药品费, valuedata[1].药品费, valuedata[2].药品费, valuedata[3].药品费, valuedata[4].药品费, valuedata[5].药品费, valuedata[6].药品费],
                                ['人均耗材费', valuedata[0].耗材费, valuedata[1].耗材费, valuedata[2].耗材费, valuedata[3].耗材费, valuedata[4].耗材费, valuedata[5].耗材费, valuedata[6].耗材费],
                                ['人均检验费', valuedata[0].检验费, valuedata[1].检验费, valuedata[2].检验费, valuedata[3].检验费, valuedata[4].检验费, valuedata[5].检验费, valuedata[6].检验费],
                                ['人均检查费', valuedata[0].检查费, valuedata[1].检查费, valuedata[2].检查费, valuedata[3].检查费, valuedata[4].检查费, valuedata[5].检查费, valuedata[6].检查费],
                                ['人均资料费', valuedata[0].资料费, valuedata[1].资料费, valuedata[2].资料费, valuedata[3].资料费, valuedata[4].资料费, valuedata[5].资料费, valuedata[6].资料费],
                                ['人均其他', valuedata[0].其他, valuedata[1].其他, valuedata[2].其他, valuedata[3].其他, valuedata[4].其他, valuedata[5].其他, valuedata[6].其他]
                            ]
                        },
                        xAxis: { type: 'category' },
                        yAxis: { gridIndex: 0 },
                        grid: { top: '55%' },
                        series: [
                            {
                                type: 'line',
                                smooth: true,
                                seriesLayoutBy: 'row',
                                emphasis: { focus: 'series' }
                            },
                            {
                                type: 'line',
                                smooth: true,
                                seriesLayoutBy: 'row',
                                emphasis: { focus: 'series' }
                            },
                            {
                                type: 'line',
                                smooth: true,
                                seriesLayoutBy: 'row',
                                emphasis: { focus: 'series' }
                            },
                            {
                                type: 'line',
                                smooth: true,
                                seriesLayoutBy: 'row',
                                emphasis: { focus: 'series' }
                            },
                            {
                                type: 'line',
                                smooth: true,
                                seriesLayoutBy: 'row',
                                emphasis: { focus: 'series' }
                            },
                            {
                                type: 'line',
                                smooth: true,
                                seriesLayoutBy: 'row',
                                emphasis: { focus: 'series' }
                            },
                            {
                                type: 'line',
                                smooth: true,
                                seriesLayoutBy: 'row',
                                emphasis: { focus: 'series' }
                            },
                            {
                                type: 'pie',
                                id: 'pie',
                                radius: '30%',
                                center: ['50%', '25%'],
                                emphasis: {
                                    focus: 'self'
                                },
                                label: {
                                     formatter: "{b}: {@('@')" + ajaxresp[0].nf+"} ({d}%)"
                                },
                                encode: {
                                    itemName: 'product',
                                    value: ajaxresp[0].年份,
                                    tooltip: ajaxresp[0].年份
                                }
                            }
                        ]
                    };

                    myChart.on('updateAxisPointer', function (event) {
                        const xAxisInfo = event.axesInfo[0];
                        if (xAxisInfo) {
                            const dimension = xAxisInfo.value + 1;
                            myChart.setOption({
                                series: {
                                    id: 'pie',
                                    label: {
                                        formatter: '{b}: {@("@")[' + dimension + ']} ({d}%)'
                                    },
                                    encode: {
                                        value: dimension,
                                        tooltip: dimension
                                    }
                                }
                            });
                        }
                    });
                    myChart.setOption(option);
                });
            }
        });
        
    }
    function submit() {
        getData();//banner
        $("#gridJSListmzfyflfx").jqGrid('setGridParam', {
            postData: getSearchData(),
        }).trigger('reloadGrid');
        $("#gridJSListhzrjfyfx").jqGrid('setGridParam', {
            postData: getSearchData(),
        }).trigger('reloadGrid');
        gridJSListData();
    }
    function gridJSListData() {
        var gridSort = 'CreateTime asc';
        var $gridJsList = $("#gridJSListmzfyflfx");
        $gridJsList.dataGrid({
            height: $(window).height() * 0.5 - 140,
            autowidth: true,//如果shrinkToFit为true且设置了width值，则每列宽度会根据width成比例缩放；
            shrinkToFit: true, //如果设为true，则Grid的宽度会根据父容器的宽度自动重算。**
            url: "/DeanInquiryManage/OutpatientCostAnalysis/GetMzfyflfx",
            postData: getSearchData(),
            colModel: [
                { label: '收入分类', name: 'srfl', align: 'left' },
                { label: '金额', name: 'je', align: 'left' }
            ],
            sortname: gridSort,
            viewrecords: true
        });

        var gridSort = 'CreateTime asc';
        var $gridJsList = $("#gridJSListhzrjfyfx");
        $gridJsList.dataGrid({
            height: $(window).height() * 0.5 - 140,
            autowidth: true,//如果shrinkToFit为true且设置了width值，则每列宽度会根据width成比例缩放；
            shrinkToFit: true, //如果设为true，则Grid的宽度会根据父容器的宽度自动重算。**
            url: "/DeanInquiryManage/OutpatientCostAnalysis/GetHzrjfyfx",
            postData: getSearchData(),
            colModel: [
                { label: '人均费用分类', name: 'srfl', align: 'left' },
                { label: '金额', name: 'je', align: 'left' }
            ],
            sortname: gridSort,
            viewrecords: true
        });

    }

    function initEcharts() {
        var myChart1 = echarts.init(document.getElementById('main1'));

        myChart1.setOption(option1);
    };
    
</script>
